package com.ruicar.afs.jobadmin.controller;

import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.jobadmin.service.AfsJobService;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * The type IndexController
 * <p>Description: </p>
 *
 * @author Fzero
 * @version 1.0
 * @date Created on 2020.06.13 14:17:12
 * @since 1.0
 */
@Controller
public class IndexController {

    /**
     * Afs job service
     * <p>Description: </p>
     */
    @Resource
    private AfsJobService afsJobService;


    /**
     * Chart info response
     *
     * @param startDate start date
     * @param endDate   end date
     * @return the response
     */
    @RequestMapping("/chartInfo")
    @ResponseBody
    public IResponse<Map<String, Object>> chartInfo(Date startDate, Date endDate) {
        return IResponse.success(afsJobService.chartInfo(startDate, endDate));
    }


    /**
     * Init binder *
     *
     * @param binder binder
     */
    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }

}
